package com.mby.utils;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.mby.entity.Push;
import io.rong.RongCloud;
import io.rong.models.response.TokenResult;
import io.rong.models.user.UserModel;
import net.dongliu.requests.Header;
import net.dongliu.requests.Requests;

import java.util.Date;

/**
 * Created by noah on 2018/5/2.
 */
public class MbyPush {

    private final static String urlStr = "http://push.themobiyun.com/push-service/send-one-push";

    public static void sentOnePushToLive(Push push){
        if(push.getPlatform().equals(WebConstant.PUSH_PLATFORM_IOS)){
            push.setEnv(WebConstant.PUSH_ENV);
            push.setAccessId(WebConstant.LIVE_ACCESSID_IOS);
            push.setSecretKey(WebConstant.LIVE_SECRETKEY_IOS);
        }

        if(push.getPlatform().equals(WebConstant.PUSH_PLATFORM_ANDROID)){
            push.setAccessId(WebConstant.LIVE_ACCESSID_ANDROID);
            push.setSecretKey(WebConstant.LIVE_SECRETKEY_ANDROID);
            push.setIntent("rong://com.mobiyun.dealer/conversation/group?targetId="+push.getGroupId());
        }
        JSONObject result = Requests.post(urlStr)
                .headers(new Header("content-type","application/json;charset=UTF-8"))
                .verify(false)
                .body(JSON.toJSONString(push))
                .send()
                .readToJson(JSONObject.class);
        System.out.println(result);
    }

    public static void sentOnePushToCsApp(Push push){
        if(push.getPlatform().equals(WebConstant.PUSH_PLATFORM_IOS)){
            push.setEnv(WebConstant.PUSH_ENV);
            push.setAccessId(WebConstant.CS_ACCESSID_IOS.get(push.getBrandId()));
            push.setSecretKey(WebConstant.CS_SECRETKEY_IOS.get(push.getBrandId()));
        }

        if(push.getPlatform().equals(WebConstant.PUSH_PLATFORM_ANDROID)){
            push.setAccessId(WebConstant.CS_ACCESSID_ANDROID.get(push.getBrandId()));
            push.setSecretKey(WebConstant.CS_SECRETKEY_ANDROID.get(push.getBrandId()));
        }
        JSONObject result = Requests.post(urlStr)
                .headers(new Header("content-type","application/json;charset=UTF-8"))
                .verify(false)
                .body(JSON.toJSONString(push))
                .send()
                .readToJson(JSONObject.class);
        System.out.println(result);
    }

}
